import Mock from "mockjs";
import { MockMethod } from "vite-plugin-mock";
import utils from "../../../src/utils/utils";
import contextPath from "../../context-path";
const Random = Mock.Random;

Mock.Random.extend({
  phone: function () {
    var phonePrefixs = ["138", "135", "189"]; // 自己写前缀哈
    return this.pick(phonePrefixs) + Mock.mock(/\d{8}/); //Number()
  },
});

export default [
  {
    url: contextPath.VITE_API_ADMIN_CONTEXT_PATH + "/admin/api/account.listing",
    method: "post",
    response: (options) => {
      const rows: any[] = [];
      const total = 112;
      let cnt = options.body.rows;
      if (options.body.rows * options.body.page > total) {
        cnt = total - options.body.rows * (options.body.page - 1);
      }
      for (let i = 0; i < cnt; i++) {
        const template = {
          name: Random.cname(),
          accountId: Mock.mock({
            "regexp|3": /\d{5,10}\-/,
          }).regexp,
          account: Random.email(),
          employeeNumber: Random.natural(),
          orgName: Random.region(),
          deptName: Random.city(),
          roles: Mock.mock({
            "array|1-2": [
              {
                orderIndex: 0,
                roleCode: "ROLE_SYS_ADMIN",
                roleName: "系统管理员",
              },
              {
                orderIndex: 2,
                roleCode: "ROLE_SYS_USER",
                roleName: "系统用户",
              },
            ],
          }).array,
          status: Mock.mock({
            "array|1": [0, 1],
          }).array,
        };
        rows.push(template);
      }

      return {
        code: 200,
        total: total,
        rows: rows,
      };
    },
  },

  {
    url:
      contextPath.VITE_API_ADMIN_CONTEXT_PATH +
      "/admin/api/account.current.get",
    method: "post",
    response: (options) => {
      const template = {
        accountId: Random.guid(),
        account: Random.email(),
        name: Random.cname(),
        gender: Mock.mock({
          "array|1": [0, 1, 2],
        }).array,
        employeeNumber: Random.natural(),
        orgName: Random.region(),
        orgCode: Random.string("upper", 5),
        deptName: Random.city(),
        deptCode: Random.string("upper", 5),
        mobile: Random.phone(),
        status: Mock.mock({
          "array|1": [0, 1],
        }).array,
        roles: [
          {
            orderIndex: 0,
            roleName: Random.string("upper", 5),
            roleCode: Random.natural(60, 1000),
          },
          {
            orderIndex: 1,
            roleName: Random.string("upper", 5),
            roleCode: Random.natural(60, 1000),
          },
          {
            orderIndex: 2,
            roleName: Random.string("upper", 5),
            roleCode: Random.natural(60, 1000),
          },
        ],
      };
      return {
        code: 200,
        message: "",
        data: template,
      };
    },
  },

  {
    url: contextPath.VITE_API_ADMIN_CONTEXT_PATH + "/admin/api/account.get",
    method: "post",
    response: (options) => {
      const template = {
        accountId: Random.guid(),
        account: Random.email(),
        name: Random.cname(),
        gender: Mock.mock({
          "array|1": [0, 1, 2],
        }).array,
        employeeNumber: Random.natural(),
        orgName: Random.region(),
        orgCode: Random.string("upper", 5),
        deptName: Random.city(),
        deptCode: Random.string("upper", 5),
        status: Mock.mock({
          "array|1": [0, 1],
        }).array,
      };
      return {
        code: 200,
        message: "",
        data: template,
      };
    },
  },
  {
    url:
      contextPath.VITE_API_ADMIN_CONTEXT_PATH +
      "/admin/api/account.extension.get",
    method: "post",
    response: (options) => {
      const template = {
        accountId: Random.guid(),
        alias: Random.cname(),
        avatarUrl: "",
        // birthday: Random.date("yyyy-MM-dd"),
        birthday: "",
        idCard: Random.natural(110105199600000000, 110105199700000000),
        email: Random.email(),
        mobile: Random.phone(),
        orgPath: "root-root,shanghai",
        deptPath: "shanghai1,shanghai12",
        description: Random.cparagraph(2),
      };
      return {
        code: 200,
        message: "",
        data: template,
      };
    },
  },
  {
    url:
      contextPath.VITE_API_ADMIN_CONTEXT_PATH + "/admin/api/account.role.all",
    method: "post",
    response: (options) => {
      let rows: any[] = [];
      for (let i = 0; i < 5; i++) {
        const template = {
          roleId: Random.guid(),
          orderIndex: Random.increment(5),
          category: Mock.mock({
            "array|1": ["APP", "SYS"],
          }).array,
          roleName: Random.string("upper", 5),
          roleCode: Random.natural(60, 1000),
          description: Random.cparagraph(2),
        };
        rows.push(template);
      }
      return {
        code: 200,
        message: "",
        data: rows,
      };
    },
  },
  {
    url: contextPath.VITE_API_ADMIN_CONTEXT_PATH + "/admin/api/account.update",
    method: "post",
    response: (options) => {
      return {
        code: 200,
        message: "",
        data: null,
      };
    },
  },

  {
    url: contextPath.VITE_API_ADMIN_CONTEXT_PATH + "/admin/api/account.delete",
    method: "post",
    response: (options) => {
      return {
        code: 200,
        message: "",
        data: null,
      };
    },
  },

  {
    url:
      contextPath.VITE_API_ADMIN_CONTEXT_PATH +
      "/admin/api/account.status.change",
    method: "post",
    response: (options) => {
      return {
        code: 200,
        message: "",
        data: null,
      };
    },
  },

  {
    url:
      contextPath.VITE_API_ADMIN_CONTEXT_PATH + "/admin/api/account.pubkey.get",
    method: "post",
    response: (options) => {
      return {
        code: 200,
        message: "",
        data: Random.guid(),
      };
    },
  },
  {
    url: contextPath.VITE_API_ADMIN_CONTEXT_PATH + "/admin/api/account.pubkey",
    method: "get",
    response: (options) => {
      return {
        code: 200,
        message: "",
        data: null,
      };
    },
  },

  {
    url:
      contextPath.VITE_API_ADMIN_CONTEXT_PATH +
      "/admin/api/account.password.change",
    method: "post",
    response: (options) => {
      return {
        code: 200,
        message: "",
        data: null,
      };
    },
  },

  {
    url:
      contextPath.VITE_API_ADMIN_CONTEXT_PATH +
      "/admin/api/account.log.listing",
    method: "post",
    response: (options) => {
      const rows: any[] = [];
      const total = 112;
      let cnt = options.body.rows;
      if (options.body.rows * options.body.page > total) {
        cnt = total - options.body.rows * (options.body.page - 1);
      }
      for (let i = 0; i < cnt; i++) {
        const template = {
          accountLogId: Random.guid(),
          accountId: Random.guid(),
          name: Random.cname(),
          catagory: Mock.mock({
            "array|1": ["app", "sys", "client"],
          }).array,
          logAction: Mock.mock({
            "array|1": ["INSERT", "UPDATE", "SEARCH", "EXPORT", "DELETE"],
          }).array,
          logLevel: Mock.mock({
            "array|1": [0, 1, 2],
          }).array,
          logInfo: Random.cparagraph(),
          businessKey: Random.guid(),
          hostId: Random.guid(),
          ipAddress: Random.ip(),
          createAccountName: Random.cname(),
          createTime: Random.datetime(),
        };
        rows.push(template);
      }

      return {
        code: 200,
        total: total,
        rows: rows,
      };
    },
  },
  {
    url: contextPath.VITE_API_ADMIN_CONTEXT_PATH + "/admin/api/account.log.get",
    method: "post",
    response: (options) => {
      const template = {
        accountLogId: Random.guid(),
        accountId: Random.guid(),
        name: Random.cname(),
        catagory: Mock.mock({
          "array|1": ["app", "sys", "client"],
        }).array,
        logAction: Mock.mock({
          "array|1": ["INSERT", "UPDATE", "SEARCH", "EXPORT", "DELETE"],
        }).array,
        logLevel: Mock.mock({
          "array|1": [0, 1, 2],
        }).array,
        logInfo: Random.cparagraph(),
        businessKey: Random.guid(),
        hostId: Random.guid(),
        ipAddress: Random.ip(),
        createAccountName: Random.cname(),
        createTime: Random.datetime(),
      };

      return {
        code: 200,
        message: "",
        data: template,
      };
    },
  },
  {
    url:
      contextPath.VITE_API_ADMIN_CONTEXT_PATH +
      "/admin/api/account.log.prev.get",
    method: "post",
    response: (options) => {
      const template = {
        accountLogId: Random.guid(),
        accountId: Random.guid(),
        name: Random.cname(),
        catagory: Mock.mock({
          "array|1": ["app", "sys", "client"],
        }).array,
        logAction: Mock.mock({
          "array|1": ["INSERT", "UPDATE", "SEARCH", "EXPORT", "DELETE"],
        }).array,
        logLevel: Mock.mock({
          "array|1": [0, 1, 2],
        }).array,
        logInfo: Random.cparagraph(),
        businessKey: Random.guid(),
        hostId: Random.guid(),
        ipAddress: Random.ip(),
        createAccountName: Random.cname(),
        createTime: Random.datetime(),
      };

      return {
        code: 200,
        message: "",
        data: template,
      };
    },
  },
  {
    url:
      contextPath.VITE_API_ADMIN_CONTEXT_PATH +
      "/admin/api/account.log.next.get",
    method: "post",
    response: (options) => {
      const template = {
        accountLogId: Random.guid(),
        accountId: Random.guid(),
        name: Random.cname(),
        catagory: Mock.mock({
          "array|1": ["app", "sys", "client"],
        }).array,
        logAction: Mock.mock({
          "array|1": ["INSERT", "UPDATE", "SEARCH", "EXPORT", "DELETE"],
        }).array,
        logLevel: Mock.mock({
          "array|1": [0, 1, 2],
        }).array,
        logInfo: Random.cparagraph(),
        businessKey: Random.guid(),
        hostId: Random.guid(),
        ipAddress: Random.ip(),
        createAccountName: Random.cname(),
        createTime: Random.datetime(),
      };

      return {
        code: 200,
        message: "",
        data: template,
      };
    },
  },
] as MockMethod[];
